import axios from "axios";
import { listToTree } from "@/utils/dataSet.js";
function generate(data) {
  const rows = {};
  const items = {};
  let data1 = data;
  data1.map((item, index) => {
    const id = (index + 1).toString();
    rows[id] = item.row;
    items[id] = item.item;
  });
  return { rows, items };
}
const getLines = async () => {
  const res = await axios.get("/api/demolink/link");
  return res.data.data.link;
};
const getListData = async () => {
  const { data } = await axios.get(`/api/dataimport/listparent`);
  return data.data.dataList;
};
const getTreeData = async () => {
  const { data } = await axios.get(`/api/dataimport/listparent`);
  return listToTree(data.data.dataList);
};
const addmethod = async (data) => {
  const res = await axios.post(`/api/dataimport/add`, data);
};
const deleteData = async (data) => {
  const res = await axios.delete(`/api/dataimport/delete`, {
    params: data,
  });
};
const updateMethod = async (data) => {
  const res = await axios.put(`/api/dataimport/updata`, data);
};
const changePath = async (data) => {
  const res = await axios.put(`/api/demolink/add`, data);
  console.log("path", res);
};
export {
  getListData,
  generate,
  addmethod,
  deleteData,
  updateMethod,
  changePath,
  getTreeData,
  getLines
};
